import json
import random

from flask import Blueprint
from RootPath import RootPath
import os
from common.YmlUtil import YmlUtil
from common.contactStr import mqttMessageContact, sqlContact

from common.RedisUtil import *
import numpy as np

from common.mysqlUtil import exc_sql

path = os.path.join(RootPath.getRootPath(), "Application.yml")
MySQLconf = YmlUtil().readYml(path,"mysql_test_74")

def dayTableGenerator():
    print(" =====dayTableGenerator=======")
    # 出水口水质分析仪
    point_value0 = {"Conductivity": json.dumps(round(random.uniform(1.5, 7.5), 2)),
                    "Turbidity": json.dumps(round(random.uniform(2, 10), 2)),
                    "ResidualChlorine": json.dumps(round(random.uniform(0.3, 0.8), 2))
                    }
    # 进水口水质分析仪
    point_value1 = {"Conductivity": json.dumps(round(random.uniform(1.5, 7.5), 2)),
                    "Turbidity": json.dumps(round(random.uniform(2, 10), 2)),
                    "ResidualChlorine": json.dumps(round(random.uniform(0.5, 0.75), 2))
                    }
    # 进水口流量计
    jk_value = {"InstantaneousFlow": json.dumps(round(random.uniform(100, 800), 2)),
                    "CumulativeFlow": json.dumps(round(random.uniform(500, 50000), 2))
                    }
    jk_value1 = {"No1InstantaneousFlow": json.dumps(round(random.uniform(100, 800), 2)),
                    "No1CumulativeFlow": json.dumps(round(random.uniform(500, 50000), 2))
                    }
    jk_value2 = {"No2InstantaneousFlow": json.dumps(round(random.uniform(100, 800), 2)),
                    "No2CumulativeFlow": json.dumps(round(random.uniform(500, 50000), 2))
                    }
    jk_value3 = {"No3InstantaneousFlow": json.dumps(round(random.uniform(100, 800), 2)),
                 "No3CumulativeFlow": json.dumps(round(random.uniform(500, 50000), 2))
                 }
    jk_value4 = {"No4InstantaneousFlow": json.dumps(round(random.uniform(100, 800), 2)),
                 "No4CumulativeFlow": json.dumps(round(random.uniform(500, 50000), 2))
                 }

    # 出水口流量计

    ck_value = {"No5InstantaneousFlow": json.dumps(round(random.uniform(100, 800), 2)),
                "No5CumulativeFlow": json.dumps(round(random.uniform(500, 50000), 2))
                }
    ck_value1 = {"No6InstantaneousFlow": json.dumps(round(random.uniform(100, 800), 2)),
                 "No6CumulativeFlow": json.dumps(round(random.uniform(500, 50000), 2))
                 }
    ck_value2 = {"No7InstantaneousFlow": json.dumps(round(random.uniform(100, 800), 2)),
                 "No7CumulativeFlow": json.dumps(round(random.uniform(500, 50000), 2))
                 }
    ck_value3 = {"No8InstantaneousFlow": json.dumps(round(random.uniform(100, 800), 2)),
                 "No8CumulativeFlow": json.dumps(round(random.uniform(500, 50000), 2))
                 }


    deviceID = ["CSKSZFXY20210329", "JSKSZFXY20210329",
                "CSKSSLIJ20210329", "202105141027","202105141029","202105141030",
                "JSKSSLIJ1","202105141021","202105141023","202105141025","202105141026"]
    point_value = [point_value0, point_value1,
                   ck_value3,ck_value,ck_value1,ck_value2,
                   jk_value,jk_value1,jk_value2,jk_value3,jk_value4]

    for i in range(len(deviceID)):

        sqldata = sqlContact(deviceID[i], point_value[i],'day_')
        exc_sql(sqldata, MySQLconf)



